package com.cqc.jdk7;

import org.junit.Test;

public class SwitchTest {
    /**
     * switch支持String
     */
    @Test
    public void f1() {
        int flag;
        String gender = "男";
        switch (gender) {
            case "男":
                flag = 1;
                break;
            case "女":
                flag = 2;
                break;
            case "太监":
                flag = 3;
                break;
            default:
                flag = 0;
        }
        System.out.println(flag);
    }

    /**
     * 如果不加break,就会一直往下走，走到break才停止
     */
    @Test
    public void f2() {
        String a = "10";
        switch (a) {
            case "10":
                System.out.println(10);
            case "11": {
                System.out.println(11);
            }
            case "1":
                System.out.println(1);
                break;
            case "2":
                System.out.println(2);
                break;
            default:
                System.out.println("other");
        }
    }
}
